include img.mk
include bin.mk
include agent.mk
include deploy.mk
.PHONY: all build

# project relate variables
PROJECTNAME=$(shell basename "$(PWD)")
DOCKER_REGISTRY="152.136.134.100:10048"
DEPLOY="deploy/helm/manager/v0.2/templates"

# Go related variables.
GOBASE=$(shell pwd)

# prod or dev compile mode
MODE ?= prod

managerimgs: glue-srvpimg glue-srvmimg glue-cronimg glue-mqueryimg apiserverimg glue-datasyncerimg

# bins
glue-srvp:
	APP=$@ make -s $(MODE)

glue-srvm:
	APP=$@ make -s $(MODE)

agent:
	APP=$@ make -s $(MODE)

transfer:
	APP=$@ make -s $(MODE)

# images
glue-srvpimg:
	$(patsubst %img, APP=%, $@) make -s image

cleanimg_glue-srvp:
	$(patsubst cleanimg_%, APP=%, $@) make -s cleanimg

glue-srvmimg:
	$(patsubst %img, APP=%, $@) make -s image

cleanimg_glue-srvm:
	$(patsubst cleanimg_%, APP=%, $@) make -s cleanimg

glue-cronimg:
	$(patsubst %img, APP=%, $@) make -s image

cleanimg_glue-cron:
	$(patsubst cleanimg_%, APP=%, $@) make -s cleanimg

glue-mqueryimg:
	$(patsubst %img, APP=%, $@) make -s image

cleanimg_glue-mquery:
	$(patsubst %img, APP=%, $@) make -s cleanimg

glue-datasyncerimg:
	$(patsubst %img, APP=%, $@) make -s image

cleanimg_glue-datasyncer:
	$(patsubst %img, APP=%, $@) make -s cleanimg

apiserverimg:
	$(patsubst %img, APP=%, $@) make -s image

cleanimg_apiserver:
	$(patsubst %img, APP=%, $@) make -s cleanimg

transferimg:
	$(patsubst %img, APP=%, $@) make -s image

cleanimg_transfer:
	$(patsubst cleanimg_%, APP=%, $@) make -s cleanimg

cleanimg_agent:
	$(patsubst cleanimg_%, APP=%, $@) make -s cleanimg

deploy_glue-srvp: glue-srvpimg
	@kubectl delete -f $(GOBASE)/$(DEPLOY)/glue-srvp.yaml --ignore-not-found=true
	@kubectl apply -f $(GOBASE)/$(DEPLOY)/glue-srvp.yaml

deploy_glue-srvm: glue-srvmimg
	@kubectl delete -f $(GOBASE)/$(DEPLOY)/glue-srvm.yaml --ignore-not-found=true
	@kubectl apply -f $(GOBASE)/$(DEPLOY)/glue-srvm.yaml

deploy_stream2:
	@go build -mod vendor -o $(GOBASE)/deploy/docker/stream2 $(GOBASE)/cmd/manager/stream2/main.go
	@chmod a+x $(GOBASE)/deploy/docker/stream2
	@docker build --build-arg EXEC_FILE="stream2" -t glue-stream2:latest $(GOBASE)/deploy/docker/
	@kubectl delete -f $(GOBASE)/$(DEPLOY)/stream-prom.yaml --ignore-not-found=true
	@kubectl apply -f $(GOBASE)/$(DEPLOY)/stream-prom.yaml

deploy_frpc:
	@docker build -t frpc:latest  $(GOBASE)/deploy/example/frp/
	@kubectl delete -f $(GOBASE)/deploy/example/frpc.yaml --ignore-not-found=true
	@kubectl apply -f $(GOBASE)/deploy/example/frpc.yaml

test_env:
	echo $(AGENT_APP)

# glue-srvm:
# 	@go build -mod vendor -o $(GOBASE)/deploy/docker/glue-srvm $(GOBASE)/cmd/glue-srvm/main.go
# 	@chmod a+x $(GOBASE)/deploy/docker/glue-srvm
# 	@docker build --build-arg EXEC_FILE="glue-srvm" -t glue-srvm:latest $(GOBASE)/deploy/docker/
# 	@kubectl delete -f $(GOBASE)/$(DEPLOY)/glue-srvm.yaml
# 	@kubectl apply -f $(GOBASE)/$(DEPLOY)/glue-srvm.yaml

# glue-cron:
# 	@go build -mod vendor -o $(GOBASE)/deploy/docker/glue-cron $(GOBASE)/cmd/glue-cron/main.go
# 	@chmod a+x $(GOBASE)/deploy/docker/glue-cron
# 	@docker build --build-arg EXEC_FILE="glue-cron" -t glue-cron:latest $(GOBASE)/deploy/docker/
# 	@kubectl delete -f $(GOBASE)/$(DEPLOY)/glue-cron.yaml
# 	@kubectl apply -f $(GOBASE)/$(DEPLOY)/glue-cron.yaml

# glue-mquery:
# 	@go build -mod vendor -o $(GOBASE)/deploy/docker/glue-mquery $(GOBASE)/cmd/glue-mquery/main.go
# 	@chmod a+x $(GOBASE)/deploy/docker/glue-mquery
# 	@docker build --build-arg EXEC_FILE="glue-mquery" -t glue-mquery:latest $(GOBASE)/deploy/docker/
# 	@kubectl delete -f $(GOBASE)/$(DEPLOY)/glue-mquery.yaml
# 	@kubectl apply -f $(GOBASE)/$(DEPLOY)/glue-mquery.yaml

